/*
 * Copyright (C) 2012 The Yuike Mobile Develop Common Framework Project
 *
 * YkAnimationSequence.m
 * 
 * @brief: 		一堆动画播放的类
 * 
 * @author   	wanggang
 * @date     	2012-1-5
 */

#import "YkAnimationSequence.h"
#import "header.h"

@interface YkAnimationStep(hidden)
- (NSArray*) animationStepArray;
@end

@interface YkAnimationSequence()
@property (nonatomic, strong, readwrite) NSArray* steps;
@end

@implementation YkAnimationSequence

@synthesize steps;

+ (id) sequenceWithSteps:(YkAnimationStep*)first, ... {
	YkAnimationSequence* instance = [[self alloc] init];
	if (instance) {
		NSMutableArray* tempSteps = [[NSMutableArray alloc] initWithCapacity:10];
		va_list args;
		va_start(args, first);
        if (first) {
           [tempSteps insertObject:first atIndex:0];
        }
		
		YkAnimationStep* aStep;
		while ((aStep = va_arg(args, YkAnimationStep*))) {
            if (!aStep) {
                continue;
            }
			[tempSteps insertObject:aStep atIndex:0];
		}
		instance.steps = [NSArray arrayWithArray:tempSteps];
		va_end(args);        
        YRelease(tempSteps);
	}
	return [instance autorelease];
}


#pragma mark - property override

- (void) setDelay:(NSTimeInterval)delay 
{
}

- (void) setDuration:(NSTimeInterval)duration 
{
}

- (void) setOptions:(UIViewAnimationOptions)options 
{
}

- (NSArray*) animationStepArray {
	NSMutableArray* array = [NSMutableArray arrayWithCapacity:[self.steps count]];
	for (YkAnimationStep* current in self.steps) {
		[array addObjectsFromArray:[current animationStepArray]];
	}
	return array;
}

#pragma mark - print

- (NSString*) description {
	NSMutableString* sequenceBody = [[NSMutableString alloc] initWithCapacity:100*[self.steps count]];
	for (YkAnimationStep* step_ in self.steps) {
		[sequenceBody appendString:[step_ description]];
	}
	
	[sequenceBody replaceOccurrencesOfString:@"\n"
                                  withString:@"\n  "
                                     options:NSCaseInsensitiveSearch
                                       range:NSMakeRange(0, [sequenceBody length])];
    
    [sequenceBody autorelease];
	return [NSString stringWithFormat:@"\n(sequence:%@\n)", sequenceBody];
}

-(void) dealloc
{
    YRelease(steps);
    [super dealloc];
}

@end

